<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.4.0-alpha - src/lstring.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - lstring.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.4.0-alpha</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">128</td>
            <td class="headerCovTableEntry">138</td>
            <td class="headerCovTableEntryHi">92.8 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:19</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: lstring.c $
<span class="lineNum">       3 </span>            : ** String table (keeps all strings handled by Lua)
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define lstring_c
<span class="lineNum">       8 </span>            : #define LUA_CORE
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &quot;ldebug.h&quot;
<span class="lineNum">      18 </span>            : #include &quot;ldo.h&quot;
<span class="lineNum">      19 </span>            : #include &quot;lmem.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      21 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      22 </span>            : #include &quot;lstring.h&quot;
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            : 
<span class="lineNum">      25 </span>            : /*
<span class="lineNum">      26 </span>            : ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to
<span class="lineNum">      27 </span>            : ** compute its hash
<span class="lineNum">      28 </span>            : */
<span class="lineNum">      29 </span>            : #if !defined(LUAI_HASHLIMIT)
<span class="lineNum">      30 </span>            : #define LUAI_HASHLIMIT          5
<span class="lineNum">      31 </span>            : #endif
<span class="lineNum">      32 </span>            : 
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span>            : 
<span class="lineNum">      35 </span>            : /*
<span class="lineNum">      36 </span>            : ** Maximum size for string table.
<span class="lineNum">      37 </span>            : */
<span class="lineNum">      38 </span>            : #define MAXSTRTB        cast_int(luaM_limitN(MAX_INT, TString*))
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            : /*
<span class="lineNum">      42 </span>            : ** equality for long strings
<span class="lineNum">      43 </span>            : */
<span class="lineNum">      44 </span><span class="lineCov">        776 : int luaS_eqlngstr (TString *a, TString *b) {</span>
<span class="lineNum">      45 </span><span class="lineCov">        776 :   size_t len = a-&gt;u.lnglen;</span>
<span class="lineNum">      46 </span>            :   lua_assert(a-&gt;tt == LUA_TLNGSTR &amp;&amp; b-&gt;tt == LUA_TLNGSTR);
<span class="lineNum">      47 </span><span class="lineCov">        998 :   return (a == b) ||  /* same instance or... */</span>
<span class="lineNum">      48 </span><span class="lineCov">        222 :     ((len == b-&gt;u.lnglen) &amp;&amp;  /* equal length and ... */</span>
<span class="lineNum">      49 </span><span class="lineCov">        195 :      (memcmp(getstr(a), getstr(b), len) == 0));  /* equal contents */</span>
<span class="lineNum">      50 </span>            : }
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span>            : 
<span class="lineNum">      53 </span><span class="lineCov">     102888 : unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {</span>
<span class="lineNum">      54 </span><span class="lineCov">     102888 :   unsigned int h = seed ^ cast_uint(l);</span>
<span class="lineNum">      55 </span><span class="lineCov">     102888 :   size_t step = (l &gt;&gt; LUAI_HASHLIMIT) + 1;</span>
<span class="lineNum">      56 </span><span class="lineCov">     755314 :   for (; l &gt;= step; l -= step)</span>
<span class="lineNum">      57 </span><span class="lineCov">     652426 :     h ^= ((h&lt;&lt;5) + (h&gt;&gt;2) + cast_byte(str[l - 1]));</span>
<span class="lineNum">      58 </span><span class="lineCov">     102888 :   return h;</span>
<span class="lineNum">      59 </span>            : }
<span class="lineNum">      60 </span>            : 
<span class="lineNum">      61 </span>            : 
<span class="lineNum">      62 </span><span class="lineCov">       1467 : unsigned int luaS_hashlongstr (TString *ts) {</span>
<span class="lineNum">      63 </span>            :   lua_assert(ts-&gt;tt == LUA_TLNGSTR);
<span class="lineNum">      64 </span><span class="lineCov">       1467 :   if (ts-&gt;extra == 0) {  /* no hash? */</span>
<span class="lineNum">      65 </span><span class="lineCov">        380 :     ts-&gt;hash = luaS_hash(getstr(ts), ts-&gt;u.lnglen, ts-&gt;hash);</span>
<span class="lineNum">      66 </span><span class="lineCov">        380 :     ts-&gt;extra = 1;  /* now it has its hash */</span>
<span class="lineNum">      67 </span>            :   }
<span class="lineNum">      68 </span><span class="lineCov">       1467 :   return ts-&gt;hash;</span>
<span class="lineNum">      69 </span>            : }
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            : 
<span class="lineNum">      72 </span><span class="lineCov">        255 : static void tablerehash (TString **vect, int osize, int nsize) {</span>
<span class="lineNum">      73 </span>            :   int i;
<span class="lineNum">      74 </span><span class="lineCov">      43903 :   for (i = osize; i &lt; nsize; i++)  /* clear new elements */</span>
<span class="lineNum">      75 </span><span class="lineCov">      43648 :     vect[i] = NULL;</span>
<span class="lineNum">      76 </span><span class="lineCov">      30079 :   for (i = 0; i &lt; osize; i++) {  /* rehash old part of the array */</span>
<span class="lineNum">      77 </span><span class="lineCov">      29824 :     TString *p = vect[i];</span>
<span class="lineNum">      78 </span><span class="lineCov">      29824 :     vect[i] = NULL;</span>
<span class="lineNum">      79 </span><span class="lineCov">      59648 :     while (p) {  /* for each string in the list */</span>
<span class="lineNum">      80 </span><span class="lineCov">      29824 :       TString *hnext = p-&gt;u.hnext;  /* save next */</span>
<span class="lineNum">      81 </span><span class="lineCov">      29824 :       unsigned int h = lmod(p-&gt;hash, nsize);  /* new position */</span>
<span class="lineNum">      82 </span><span class="lineCov">      29824 :       p-&gt;u.hnext = vect[h];  /* chain it into array */</span>
<span class="lineNum">      83 </span><span class="lineCov">      29824 :       vect[h] = p;</span>
<span class="lineNum">      84 </span><span class="lineCov">      29824 :       p = hnext;</span>
<span class="lineNum">      85 </span>            :     }
<span class="lineNum">      86 </span>            :   }
<span class="lineNum">      87 </span><span class="lineCov">        255 : }</span>
<span class="lineNum">      88 </span>            : 
<span class="lineNum">      89 </span>            : 
<span class="lineNum">      90 </span>            : /*
<span class="lineNum">      91 </span>            : ** Resize the string table. If allocation fails, keep the current size.
<span class="lineNum">      92 </span>            : ** (This can degrade performance, but any non-zero size should work
<span class="lineNum">      93 </span>            : ** correctly.)
<span class="lineNum">      94 </span>            : */
<span class="lineNum">      95 </span><span class="lineCov">        147 : void luaS_resize (lua_State *L, int nsize) {</span>
<span class="lineNum">      96 </span><span class="lineCov">        147 :   stringtable *tb = &amp;G(L)-&gt;strt;</span>
<span class="lineNum">      97 </span><span class="lineCov">        147 :   int osize = tb-&gt;size;</span>
<span class="lineNum">      98 </span>            :   TString **newvect;
<span class="lineNum">      99 </span><span class="lineCov">        147 :   if (nsize &lt; osize)  /* shrinking table? */</span>
<span class="lineNum">     100 </span><span class="lineNoCov">          0 :     tablerehash(tb-&gt;hash, osize, nsize);  /* depopulate shrinking part */</span>
<span class="lineNum">     101 </span><span class="lineCov">        147 :   newvect = luaM_reallocvector(L, tb-&gt;hash, osize, nsize, TString*);</span>
<span class="lineNum">     102 </span><span class="lineCov">        147 :   if (unlikely(newvect == NULL)) {  /* reallocation failed? */</span>
<span class="lineNum">     103 </span><span class="lineNoCov">          0 :     if (nsize &lt; osize)  /* was it shrinking table? */</span>
<span class="lineNum">     104 </span><span class="lineNoCov">          0 :       tablerehash(tb-&gt;hash, nsize, osize);  /* restore to original size */</span>
<span class="lineNum">     105 </span>            :     /* leave table as it was */
<span class="lineNum">     106 </span>            :   }
<span class="lineNum">     107 </span>            :   else {  /* allocation succeeded */
<span class="lineNum">     108 </span><span class="lineCov">        147 :     tb-&gt;hash = newvect;</span>
<span class="lineNum">     109 </span><span class="lineCov">        147 :     tb-&gt;size = nsize;</span>
<span class="lineNum">     110 </span><span class="lineCov">        147 :     if (nsize &gt; osize)</span>
<span class="lineNum">     111 </span><span class="lineCov">        147 :       tablerehash(newvect, osize, nsize);  /* rehash for new size */</span>
<span class="lineNum">     112 </span>            :   }
<span class="lineNum">     113 </span><span class="lineCov">        147 : }</span>
<span class="lineNum">     114 </span>            : 
<span class="lineNum">     115 </span>            : 
<span class="lineNum">     116 </span>            : /*
<span class="lineNum">     117 </span>            : ** Clear API string cache. (Entries cannot be empty, so fill them with
<span class="lineNum">     118 </span>            : ** a non-collectable string.)
<span class="lineNum">     119 </span>            : */
<span class="lineNum">     120 </span><span class="lineCov">        618 : void luaS_clearcache (global_State *g) {</span>
<span class="lineNum">     121 </span>            :   int i, j;
<span class="lineNum">     122 </span><span class="lineCov">      33372 :   for (i = 0; i &lt; STRCACHE_N; i++)</span>
<span class="lineNum">     123 </span><span class="lineCov">      98262 :     for (j = 0; j &lt; STRCACHE_M; j++) {</span>
<span class="lineNum">     124 </span><span class="lineCov">      65508 :       if (iswhite(g-&gt;strcache[i][j]))  /* will entry be collected? */</span>
<span class="lineNum">     125 </span><span class="lineCov">        583 :         g-&gt;strcache[i][j] = g-&gt;memerrmsg;  /* replace it with something fixed */</span>
<span class="lineNum">     126 </span>            :     }
<span class="lineNum">     127 </span><span class="lineCov">        618 : }</span>
<span class="lineNum">     128 </span>            : 
<span class="lineNum">     129 </span>            : 
<span class="lineNum">     130 </span>            : /*
<span class="lineNum">     131 </span>            : ** Initialize the string table and the string cache
<span class="lineNum">     132 </span>            : */
<span class="lineNum">     133 </span><span class="lineCov">        108 : void luaS_init (lua_State *L) {</span>
<span class="lineNum">     134 </span><span class="lineCov">        108 :   global_State *g = G(L);</span>
<span class="lineNum">     135 </span>            :   int i, j;
<span class="lineNum">     136 </span><span class="lineCov">        108 :   stringtable *tb = &amp;G(L)-&gt;strt;</span>
<span class="lineNum">     137 </span><span class="lineCov">        108 :   tb-&gt;hash = luaM_newvector(L, MINSTRTABSIZE, TString*);</span>
<span class="lineNum">     138 </span><span class="lineCov">        108 :   tablerehash(tb-&gt;hash, 0, MINSTRTABSIZE);  /* clear array */</span>
<span class="lineNum">     139 </span><span class="lineCov">        108 :   tb-&gt;size = MINSTRTABSIZE;</span>
<span class="lineNum">     140 </span>            :   /* pre-create memory-error message */
<span class="lineNum">     141 </span><span class="lineCov">        108 :   g-&gt;memerrmsg = luaS_newliteral(L, MEMERRMSG);</span>
<span class="lineNum">     142 </span><span class="lineCov">        108 :   luaC_fix(L, obj2gco(g-&gt;memerrmsg));  /* it should never be collected */</span>
<span class="lineNum">     143 </span><span class="lineCov">       5832 :   for (i = 0; i &lt; STRCACHE_N; i++)  /* fill cache with valid strings */</span>
<span class="lineNum">     144 </span><span class="lineCov">      17172 :     for (j = 0; j &lt; STRCACHE_M; j++)</span>
<span class="lineNum">     145 </span><span class="lineCov">      11448 :       g-&gt;strcache[i][j] = g-&gt;memerrmsg;</span>
<span class="lineNum">     146 </span><span class="lineCov">        108 : }</span>
<span class="lineNum">     147 </span>            : 
<span class="lineNum">     148 </span>            : 
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            : /*
<span class="lineNum">     151 </span>            : ** creates a new string object
<span class="lineNum">     152 </span>            : */
<span class="lineNum">     153 </span><span class="lineCov">      44688 : static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {</span>
<span class="lineNum">     154 </span>            :   TString *ts;
<span class="lineNum">     155 </span>            :   GCObject *o;
<span class="lineNum">     156 </span>            :   size_t totalsize;  /* total size of TString object */
<span class="lineNum">     157 </span><span class="lineCov">      44688 :   totalsize = sizelstring(l);</span>
<span class="lineNum">     158 </span><span class="lineCov">      44688 :   o = luaC_newobj(L, tag, totalsize);</span>
<span class="lineNum">     159 </span><span class="lineCov">      44688 :   ts = gco2ts(o);</span>
<span class="lineNum">     160 </span><span class="lineCov">      44688 :   ts-&gt;hash = h;</span>
<span class="lineNum">     161 </span><span class="lineCov">      44688 :   ts-&gt;extra = 0;</span>
<span class="lineNum">     162 </span><span class="lineCov">      44688 :   getstr(ts)[l] = '\0';  /* ending 0 */</span>
<span class="lineNum">     163 </span><span class="lineCov">      44688 :   return ts;</span>
<span class="lineNum">     164 </span>            : }
<span class="lineNum">     165 </span>            : 
<span class="lineNum">     166 </span>            : 
<span class="lineNum">     167 </span><span class="lineCov">       2678 : TString *luaS_createlngstrobj (lua_State *L, size_t l) {</span>
<span class="lineNum">     168 </span><span class="lineCov">       2678 :   TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)-&gt;seed);</span>
<span class="lineNum">     169 </span><span class="lineCov">       2678 :   ts-&gt;u.lnglen = l;</span>
<span class="lineNum">     170 </span><span class="lineCov">       2678 :   return ts;</span>
<span class="lineNum">     171 </span>            : }
<span class="lineNum">     172 </span>            : 
<span class="lineNum">     173 </span>            : 
<span class="lineNum">     174 </span><span class="lineCov">      39242 : void luaS_remove (lua_State *L, TString *ts) {</span>
<span class="lineNum">     175 </span><span class="lineCov">      39242 :   stringtable *tb = &amp;G(L)-&gt;strt;</span>
<span class="lineNum">     176 </span><span class="lineCov">      39242 :   TString **p = &amp;tb-&gt;hash[lmod(ts-&gt;hash, tb-&gt;size)];</span>
<span class="lineNum">     177 </span><span class="lineCov">      43151 :   while (*p != ts)  /* find previous element */</span>
<span class="lineNum">     178 </span><span class="lineCov">       3909 :     p = &amp;(*p)-&gt;u.hnext;</span>
<span class="lineNum">     179 </span><span class="lineCov">      39242 :   *p = (*p)-&gt;u.hnext;  /* remove element from its list */</span>
<span class="lineNum">     180 </span><span class="lineCov">      39242 :   tb-&gt;nuse--;</span>
<span class="lineNum">     181 </span><span class="lineCov">      39242 : }</span>
<span class="lineNum">     182 </span>            : 
<span class="lineNum">     183 </span>            : 
<span class="lineNum">     184 </span><span class="lineCov">        147 : static void growstrtab (lua_State *L, stringtable *tb) {</span>
<span class="lineNum">     185 </span><span class="lineCov">        147 :   if (unlikely(tb-&gt;nuse == MAX_INT)) {  /* too many strings? */</span>
<span class="lineNum">     186 </span><span class="lineNoCov">          0 :     luaC_fullgc(L, 1);  /* try to free some... */</span>
<span class="lineNum">     187 </span><span class="lineNoCov">          0 :     if (tb-&gt;nuse == MAX_INT)  /* still too many? */</span>
<span class="lineNum">     188 </span><span class="lineNoCov">          0 :       luaM_error(L);  /* cannot even create a message... */</span>
<span class="lineNum">     189 </span>            :   }
<span class="lineNum">     190 </span><span class="lineCov">        147 :   if (tb-&gt;size &lt;= MAXSTRTB / 2)  /* can grow string table? */</span>
<span class="lineNum">     191 </span><span class="lineCov">        147 :     luaS_resize(L, tb-&gt;size * 2);</span>
<span class="lineNum">     192 </span><span class="lineCov">        147 : }</span>
<span class="lineNum">     193 </span>            : 
<span class="lineNum">     194 </span>            : 
<span class="lineNum">     195 </span>            : /*
<span class="lineNum">     196 </span>            : ** Checks whether short string exists and reuses it or creates a new one.
<span class="lineNum">     197 </span>            : */
<span class="lineNum">     198 </span><span class="lineCov">     102400 : static TString *internshrstr (lua_State *L, const char *str, size_t l) {</span>
<span class="lineNum">     199 </span>            :   TString *ts;
<span class="lineNum">     200 </span><span class="lineCov">     102400 :   global_State *g = G(L);</span>
<span class="lineNum">     201 </span><span class="lineCov">     102400 :   stringtable *tb = &amp;g-&gt;strt;</span>
<span class="lineNum">     202 </span><span class="lineCov">     102400 :   unsigned int h = luaS_hash(str, l, g-&gt;seed);</span>
<span class="lineNum">     203 </span><span class="lineCov">     102400 :   TString **list = &amp;tb-&gt;hash[lmod(h, tb-&gt;size)];</span>
<span class="lineNum">     204 </span>            :   lua_assert(str != NULL);  /* otherwise 'memcmp'/'memcpy' are undefined */
<span class="lineNum">     205 </span><span class="lineCov">     138746 :   for (ts = *list; ts != NULL; ts = ts-&gt;u.hnext) {</span>
<span class="lineNum">     206 </span><span class="lineCov">      96736 :     if (l == ts-&gt;shrlen &amp;&amp; (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {</span>
<span class="lineNum">     207 </span>            :       /* found! */
<span class="lineNum">     208 </span><span class="lineCov">      60390 :       if (isdead(g, ts))  /* dead (but not collected yet)? */</span>
<span class="lineNum">     209 </span><span class="lineNoCov">          0 :         changewhite(ts);  /* resurrect it */</span>
<span class="lineNum">     210 </span><span class="lineCov">      60390 :       return ts;</span>
<span class="lineNum">     211 </span>            :     }
<span class="lineNum">     212 </span>            :   }
<span class="lineNum">     213 </span>            :   /* else must create a new string */
<span class="lineNum">     214 </span><span class="lineCov">      42010 :   if (tb-&gt;nuse &gt;= tb-&gt;size) {  /* need to grow string table? */</span>
<span class="lineNum">     215 </span><span class="lineCov">        147 :     growstrtab(L, tb);</span>
<span class="lineNum">     216 </span><span class="lineCov">        147 :     list = &amp;tb-&gt;hash[lmod(h, tb-&gt;size)];  /* rehash with new size */</span>
<span class="lineNum">     217 </span>            :   }
<span class="lineNum">     218 </span><span class="lineCov">      42010 :   ts = createstrobj(L, l, LUA_TSHRSTR, h);</span>
<span class="lineNum">     219 </span><span class="lineCov">      42010 :   memcpy(getstr(ts), str, l * sizeof(char));</span>
<span class="lineNum">     220 </span><span class="lineCov">      42010 :   ts-&gt;shrlen = cast_byte(l);</span>
<span class="lineNum">     221 </span><span class="lineCov">      42010 :   ts-&gt;u.hnext = *list;</span>
<span class="lineNum">     222 </span><span class="lineCov">      42010 :   *list = ts;</span>
<span class="lineNum">     223 </span><span class="lineCov">      42010 :   tb-&gt;nuse++;</span>
<span class="lineNum">     224 </span><span class="lineCov">      42010 :   return ts;</span>
<span class="lineNum">     225 </span>            : }
<span class="lineNum">     226 </span>            : 
<span class="lineNum">     227 </span>            : 
<span class="lineNum">     228 </span>            : /*
<span class="lineNum">     229 </span>            : ** new string (with explicit length)
<span class="lineNum">     230 </span>            : */
<span class="lineNum">     231 </span><span class="lineCov">     104643 : TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {</span>
<span class="lineNum">     232 </span><span class="lineCov">     104643 :   if (l &lt;= LUAI_MAXSHORTLEN)  /* short string? */</span>
<span class="lineNum">     233 </span><span class="lineCov">     102400 :     return internshrstr(L, str, l);</span>
<span class="lineNum">     234 </span>            :   else {
<span class="lineNum">     235 </span>            :     TString *ts;
<span class="lineNum">     236 </span><span class="lineCov">       2243 :     if (unlikely(l &gt;= (MAX_SIZE - sizeof(TString))/sizeof(char)))</span>
<span class="lineNum">     237 </span><span class="lineNoCov">          0 :       luaM_toobig(L);</span>
<span class="lineNum">     238 </span><span class="lineCov">       2243 :     ts = luaS_createlngstrobj(L, l);</span>
<span class="lineNum">     239 </span><span class="lineCov">       2243 :     memcpy(getstr(ts), str, l * sizeof(char));</span>
<span class="lineNum">     240 </span><span class="lineCov">       2243 :     return ts;</span>
<span class="lineNum">     241 </span>            :   }
<span class="lineNum">     242 </span>            : }
<span class="lineNum">     243 </span>            : 
<span class="lineNum">     244 </span>            : 
<span class="lineNum">     245 </span>            : /*
<span class="lineNum">     246 </span>            : ** Create or reuse a zero-terminated string, first checking in the
<span class="lineNum">     247 </span>            : ** cache (using the string address as a key). The cache can contain
<span class="lineNum">     248 </span>            : ** only zero-terminated strings, so it is safe to use 'strcmp' to
<span class="lineNum">     249 </span>            : ** check hits.
<span class="lineNum">     250 </span>            : */
<span class="lineNum">     251 </span><span class="lineCov">      35833 : TString *luaS_new (lua_State *L, const char *str) {</span>
<span class="lineNum">     252 </span><span class="lineCov">      35833 :   unsigned int i = point2uint(str) % STRCACHE_N;  /* hash */</span>
<span class="lineNum">     253 </span>            :   int j;
<span class="lineNum">     254 </span><span class="lineCov">      35833 :   TString **p = G(L)-&gt;strcache[i];</span>
<span class="lineNum">     255 </span><span class="lineCov">      84141 :   for (j = 0; j &lt; STRCACHE_M; j++) {</span>
<span class="lineNum">     256 </span><span class="lineCov">      60385 :     if (strcmp(str, getstr(p[j])) == 0)  /* hit? */</span>
<span class="lineNum">     257 </span><span class="lineCov">      12077 :       return p[j];  /* that is it */</span>
<span class="lineNum">     258 </span>            :   }
<span class="lineNum">     259 </span>            :   /* normal route */
<span class="lineNum">     260 </span><span class="lineCov">      47512 :   for (j = STRCACHE_M - 1; j &gt; 0; j--)</span>
<span class="lineNum">     261 </span><span class="lineCov">      23756 :     p[j] = p[j - 1];  /* move out last element */</span>
<span class="lineNum">     262 </span>            :   /* new element is first in the list */
<span class="lineNum">     263 </span><span class="lineCov">      23756 :   p[0] = luaS_newlstr(L, str, strlen(str));</span>
<span class="lineNum">     264 </span><span class="lineCov">      23756 :   return p[0];</span>
<span class="lineNum">     265 </span>            : }
<span class="lineNum">     266 </span>            : 
<span class="lineNum">     267 </span>            : 
<span class="lineNum">     268 </span><span class="lineCov">        592 : Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) {</span>
<span class="lineNum">     269 </span>            :   Udata *u;
<span class="lineNum">     270 </span>            :   int i;
<span class="lineNum">     271 </span>            :   GCObject *o;
<span class="lineNum">     272 </span><span class="lineCov">        592 :   if (unlikely(s &gt; MAX_SIZE - udatamemoffset(nuvalue)))</span>
<span class="lineNum">     273 </span><span class="lineNoCov">          0 :     luaM_toobig(L);</span>
<span class="lineNum">     274 </span><span class="lineCov">        592 :   o = luaC_newobj(L, LUA_TUSERDATA, sizeudata(nuvalue, s));</span>
<span class="lineNum">     275 </span><span class="lineCov">        592 :   u = gco2u(o);</span>
<span class="lineNum">     276 </span><span class="lineCov">        592 :   u-&gt;len = s;</span>
<span class="lineNum">     277 </span><span class="lineCov">        592 :   u-&gt;nuvalue = nuvalue;</span>
<span class="lineNum">     278 </span><span class="lineCov">        592 :   u-&gt;metatable = NULL;</span>
<span class="lineNum">     279 </span><span class="lineCov">        592 :   for (i = 0; i &lt; nuvalue; i++)</span>
<span class="lineNum">     280 </span><span class="lineNoCov">          0 :     setnilvalue(&amp;u-&gt;uv[i].uv);</span>
<span class="lineNum">     281 </span><span class="lineCov">        592 :   return u;</span>
<span class="lineNum">     282 </span>            : }
<span class="lineNum">     283 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
